<?php
class Application_Model_DbTable_Order extends Zend_Db_Table_Abstract{
	protected $_name = 'tbl_order';
	protected $_primary = 'order_id';
	
	const ORDER_NEW = 0;
	const ORDER_PROCESSING = 1;
	const ORDER_PROCESSED = 2;
	
	public function getList($filters = array(),$sortType = "ASC",$sortBy = null){
		$select = $this->select()->setIntegrityCheck(false)
		->from($this->_name)
		->join("tbl_user", "order_user_id = user_id")
		;
	
		if( count($filters) > 0 ){
				
			foreach($filters as $key => $value){
				if($key=="keyword" && trim($value)!=""){
					$select->where('user_email like ?',"%$value%");
				}
				
				if($key=="fromDate" && $value!=null){
					$select->where('order_creation_time >= ?',$value);
				}
				
				if($key=="toDate" && $value!=null){
					$select->where('order_creation_time <= ?',$value);
				}
				
				if($key=="status" && ($value!=-1)){
					$select->where('order_status = ?',$value);
				}
				
			}//end foreach
		}//end if
	
		if($sortBy==null){
			$sortBy = "order_creation_time";
			$sortType = "Desc";
		}
		$select->order($sortBy . " " . $sortType);
			
		return  $this->fetchAll($select);
	}
}